package com.expoents.springboot.controller;


import com.expoents.springboot.config.RespBean;
import com.expoents.springboot.config.RespPageBean;
import com.expoents.springboot.entity.Student;
import com.expoents.springboot.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author YXC
 * @since 2022-08-23
 */
@Api(tags = "学生模块")
@RestController
@RequestMapping("/student")
public class StudentController {
  @Autowired
  private IStudentService studentService;
  
//  @ApiOperation(value = "获取所有学生信息")
//    @GetMapping("/getStudent")
//    public List<Student> getStudent(){
//        return studentService.list();
//    }
  
  @ApiOperation(value = "获取所有班级信息")
  @GetMapping("/getStudent")
  public RespPageBean getStudent(
      @RequestParam(defaultValue = "1") Integer currentPage,
      @RequestParam(defaultValue = "10") Integer size){
    return studentService.getStudentByPage(currentPage,size);
  }
  
  @ApiOperation(value = "增加学生信息")
  @PostMapping("/addStudent")
  public RespBean addStudent(@RequestBody Student student){
    if (studentService.save(student)){
      return RespBean.success("添加成功！");
    }
    return RespBean.error("添加失败！");
  }
  
  @ApiOperation(value = "更新学生信息")
  @PutMapping("/updateStudent")
  public RespBean updateStudent(@RequestBody Student student){
    if (studentService.updateById(student)){
      return RespBean.success("更新成功！");
    }
    return RespBean.error("更新失败！");
  }
  
  @ApiOperation(value = "删除学生信息")
  @DeleteMapping("/deleteStudent{id}")
  public RespBean deleteStudent(@PathVariable Integer id){
    if (studentService.removeById(id)){
      return RespBean.success("删除成功！");
    }
    return RespBean.error("删除失败！");
  }
  
}
